<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	<jsp:include page="../inc/meta.jsp"></jsp:include>
    <jsp:include page="../inc/easyui.jsp"></jsp:include>
   <style>
	.input {
		width: 300px;
		height: 25px;
		border: 1px solid #20B2AA;
	}
	</style> 
  </head>
  
    <body class="easyui-layout" fit="true">
    	<div id="content" region="center" style="overflow:hidden">
    		<form id="frmChangePassword" action="" method="post">
    		<input name="userId" type="hidden" value="${userId }"/>
    		    <div class="fa_fv" style="width: 650px; margin-top:50px;margin-right:auto;margin-left:auto">
                    <table class="fa_fv_table" border="0" cellpadding="0" cellspacing="0">
                        <colgroup>
                            <col style="width: 80px" />
                            <col style="width: 300px" />
                        </colgroup>
                        <tr>
                            <td class="fa_fv_group fa_fv_td" colspan="2">
                                <div class="fa_fv_c" style="text-align: center;">
                                    	修改密码
                                </div>
                            </td>
                        </tr>
                            <tr>
                                <th class="fa_fv_th" align="right">
                                	原密码：
<!--                                     <div class="fa_fv_c"> -->
<!--                                         <label for="EverName"> -->
<!-- 											原密码：</label> -->
<!--                                     </div> -->
                                </th>
                                <td class="fa_fv_td">
                                    <div class="fa_fv_right">
                                        <input name="oldPassword" type="password" required="true" class="easyui-validatebox input" /> 
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="fa_fv_th" align="right">
                               		 新密码：
<!--                                     <div class="fa_fv_c"> -->
<!--                                         <label for="EverName"> -->
<!-- 											新密码：</label> -->
<!--                                     </div> -->
                                </th>
                                <td class="fa_fv_td">
                                    <div class="fa_fv_right">
                                        <input id="newPassword" name="newPassword" type="password" required="true" class="easyui-validatebox input" validType="checkPassWord"/>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="fa_fv_th" align="right">
                               	 密码要求：
<!--                                     <div class="fa_fv_c"> -->
<!--                                         <label for="EverName"> -->
<!-- 											密码要求：</label> -->
<!--                                     </div> -->
                                </th>
                                <td class="fa_fv_td">
                                    <div class="fa_fv_right">
                                    <span class="required"> 密码最小长度为6位、必须包含数字与字母、 </span><br/> 
									<span class="required"> 不允许包含 @、#、$、%等特殊字符 </span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                 <th class="fa_fv_th" align="right">
                               		 确认密码：
<!--                                     <div class="fa_fv_c"> -->
<!--                                         <label for="EverName"> -->
<!-- 											确认密码：</label> -->
<!--                                     </div> -->
                                </th>
                                <td class="fa_fv_td">
                                    <div class="fa_fv_right">
                                        <input name="confirmPassword" type="password" required="true"  validtype="eqPassword[newPassword]"  class="easyui-validatebox input" />
                                    </div>
                                </td>
                            </tr>
                            
                        <tr>
                            <td class="fa_fv_group fa_fv_td" colspan="2">
                                <div class="fa_fv_c" style="text-align: center;">
                            <a class="easyui-linkbutton" iconcls="icon-save" href="javascript:doSubmit('<%=request.getContextPath()%>/account/changePassword');">
            				保存</a> 
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
    		</form>
    	</div>
    <script type="text/javascript">
    	function doSubmit(url){
    		$('#frmChangePassword').form('submit',{
    			url:url,
    			onsubmit: function () {
                    var flag = $(this).form('validate');
                    if (flag) {
                        top.showProcess(true, '温馨提示', '正在提交数据...');
                    }
                    return flag;
                },
                success: function (data) {
                    top.showProcess(false);
                    var map = $.parseJSON(data);
                    if (map.success) {
//                     	top.closeCurrentTab();
//                         top.showMsg('提示', map.msg);
//                     	 top.alertMsg('成功', map.msg+"\n"+(map.obj==null?"":map.obj));
//                          $(this).form('clear');
//                          window.location.reload();
                        location.href = "<%=request.getContextPath()%>/account/toChangePasswordSuccess";

                    }
                    else {
                    	if(map.msg == 1){
                        	top.alertMsg('错误', "原密码错误！\n"+(map.obj==null?"":map.obj));                    		
                    	}else{
                        	location.href = "<%=request.getContextPath()%>/account/toChangePasswordError?userId=${userId }";                 		
                    	}
//                         $(this).form('clear');
//                         parent.location.reload();

                    }
                },
                onLoadError: function () {
                    top.showProcess(false);
                    top.$.messager.alert('温馨提示', '由于网络或服务器太忙，提交失败，请重试！');
                }
    			
    		
    		});
    	
    	}
    </script>
    </body>
    <script type="text/javascript">
	function check(){
		var psw = $("#newPassword").val();
		if(psw.length < 6)
		    return false;
		if(/[~!@#$%^&*()_+]/.test(psw))
		    return false;
		var number = /[0-9]/.test(psw);
		var lowerCase = /[a-z]/.test(psw);
		var upperCase = /[A-Z]/.test(psw);
		if((number && lowerCase) || (number && upperCase))
		    return true;
		else
			return false;
	}
// 	function checkPass(){
// 		if(!check()){
// 			$.messager.alert("注意", "密码格式不正确!", "error");
// 		}
// 	}
	//扩展easyui表单的验证  
	$.extend($.fn.validatebox.defaults.rules, {
		checkPassWord: {
			validator: function(value){
				if(check()){
					return true;
				}else{
					return false;
				}
			},
			message: '密码格式不正确'
		}
	});
</script>
</html>
